<template>
  <el-dialog
    title="字段信息"
    :visible.sync="dialogVisible"
  >
    <el-table v-loading="table.loading" :data="table.data" border style="width: 100%">
      <el-table-column align="center" prop="field" label="名称" />
      <el-table-column align="center" prop="type" label="类型" />
      <el-table-column align="center" prop="nullField" label="是否非空" />
      <el-table-column align="center" prop="key" label="索引类型">
        <template slot-scope="{row}">
          <span v-if="row.key==='PRI'">主键</span>
          <span v-else-if="row.key==='MUL'">普通</span>
          <span v-else-if="row.key==='UNI'">唯一</span>
          <span v-else>{{ row.key }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="defaultField" label="默认值" />
      <el-table-column align="center" prop="extra" label="其它信息" />
      <el-table-column align="center" label="操作" fixed="right" width="100px">
        <el-button-group class="operation">
          <el-button type="text">详情</el-button>
        </el-button-group>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getFieldByTable } from '@/api/code-generate'

export default {
  name: 'Field',
  data() {
    return {
      dialogVisible: false,
      query: {
        tableName: null
      },
      table: {
        data: null,
        loading: false
      }
    }
  },
  methods: {
    open(tableName) {
      this.query.tableName = tableName
      this.dialogVisible = true
      this.getFieldByTableData()
    },
    getFieldByTableData() {
      getFieldByTable(this.query).then(res => {
        const rows = res.rows
        this.table.data = rows
      })
    }
  }
}
</script>

<style scoped>

</style>
